﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for EtiqaTAPolicyNumberDB
/// </summary>
/// 
namespace CE.TravelInsurance
{
    public class EtiqaTAPolicyNumberDB
    {
        public EtiqaTAPolicyNumberDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public EtiqaTAPolicyNumber GetNewPolicyNumber(Int64 ProviderCompanyId)
        {
            EtiqaTAPolicyNumber _policynumber = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderTAPolicyNumberSelectNewSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _policynumber = new EtiqaTAPolicyNumber();
                    _policynumber = FillDataRecord(_dt, 0);
                }
            }
            return _policynumber;
        }



        public Int64 UpdateIssued(Int64 _policynumberid, string OrderNumber, string AuthCode, string AuthDT, string CCTRef, string Email, string Amount)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderTAPolicyNumberIssuedUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@PolicyNumberId", _policynumberid);
            _sPara.Add("@ProviderCompanyId", 30);
            _sPara.Add("@IsIssued", true);
            _sPara.Add("@Info1", OrderNumber);
            _sPara.Add("@Info2", AuthCode);
            _sPara.Add("@Info3", AuthDT);
            _sPara.Add("@Info4", CCTRef);
            _sPara.Add("@Info5", Email);
            _sPara.Add("@Info6", Amount);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Delete()
        {
            return true;
        }

        private EtiqaTAPolicyNumber FillDataRecord(DataTable myDataTable, int RowId)
        {
            EtiqaTAPolicyNumber myPolicyNumber = new EtiqaTAPolicyNumber();
            myPolicyNumber.PolicyNumberId = Convert.ToInt64(myDataTable.Rows[RowId]["PolicyNumberId"].ToString());
            myPolicyNumber.ProviderCompanyId = Convert.ToInt32(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myPolicyNumber.PolicyNumber = myDataTable.Rows[RowId]["PolicyNumber"].ToString();
            myPolicyNumber.IsIssued = Convert.ToBoolean(myDataTable.Rows[RowId]["IsIssued"].ToString());
            myPolicyNumber.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            //myPolicyNumber.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            return myPolicyNumber;
        }
    }
}